﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using LayuiDemo.Models;
using ReaWTM.LayuiHelper.Extensions;
using ReaWTM.LayuiHelper;


namespace LayuiDemo.ViewModels.PostVMs
{
	public partial class ChildTable : BasePagedListVM<Post_View, PostSearcher>
	{
		public ChildTable()
		{
			NeedPage = false;

		}
		public List<ComboSelectListItem> AllBlogs { get; set; }
		protected override void InitVM()
		{
			AllBlogs = DC.Set<Blog>().GetSelectListItems(Wtm, y => y.Url);
		}
		protected override List<GridAction> InitGridAction()
		{
			return new List<GridAction>
			{
				this.MakeStandardAction("Post", GridActionStandardTypesEnum.AddRow, Localizer["Sys.AddRow"],"", dialogWidth: 800).SetButtonId("dd"),
				this.MakeStandardAction("Post", GridActionStandardTypesEnum.RemoveRow, Localizer["Sys.RemoveRow"], "", dialogWidth: 800),
				this.MakeRowCopyButton()
			};
		}


		protected override IEnumerable<IGridColumn<Post_View>> InitGridHeader()
		{
			return new List<GridColumn<Post_View>>{
				this.MakeGridHeader(x => x.Title).SetTextBox(this,slot:"list='browsers' onblur='slot_onblur(this)'",layVerify:"required"),
				this.MakeGridHeader(x => x.Content).SetEditType(EditTypeEnum.ComboBox,typeof(EditTypeEnum).ToListItems(null,true)),
				this.MakeGridHeaderAction(width: 200)
			};
		}

		public override IOrderedQueryable<Post_View> GetSearchQuery()
		{
			var query = DC.Set<Post>()
				.CheckContain(Searcher.Title, x => x.Title)
				.CheckContain(Searcher.Content, x => x.Content)
				.CheckEqual(Searcher.BlogId, x => x.BlogId)
				.Select(x => new Post_View
				{
					ID = x.ID,
					Title = x.Title,
					Content = x.Content,
					Url_view = x.Blog.Url,
				})
				.OrderBy(x => x.ID);
			return query;
		}

	}


}
